<script>
import CakeApi from "../../api/cake";

export default {
  emits: ["search-result"],
  data() {
    return {
      keyword: "",
    };
  },
  methods: {
    async search() {
      try {
        const api = new CakeApi();
        let res = await api.search(this.keyword);
        console.log(res);
        //从子组件向父组件传递数据
        this.$emit("search-result", res.data);
      } catch (err) {
        // console.error(err);
        // this.$myMessageBox("应用服务器访问错误！");
      }
    },
  },
};
</script>

<template>
  <div class="cake-search">
    <input
      type="text "
      title="输入搜索关键字"
      placeholder="蛋糕id或名称"
      v-model="keyword"
    />
    <button @click="search">搜索</button>
  </div>
</template>

<style scoped></style>
